package com.example.webservicecalleraxis;

import javax.xml.namespace.QName;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

/**
 * @author liwq
 * @description
 * @date 2021/11/18 9:51
 */
public class callUtils {

    public static void main(String[] args) {
        // String param = "<?xml version=\"1.0\" encoding=\"GBK\"?>\n" + " <FPXT_INPUT>\n" + " <ID>DLSB</ID>\n"
        // + " <SHMW>NTAwMTAyMjAzMTA5MjM3NjE1Cg==</SHMW>\n"
        // + "
        // <DATA>PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iR0JLIj8+CjxJTlBVVD4gCjxTSD41MDAxMDIyMDMxMDkyMzc2MTU8L1NIPiAgCjxaRkpIPjA8L1pGSkg+IAo8L0lOUFVUPgo=</DATA>\n"
        // + " </FPXT_INPUT>";
        // String respXML = callWebServiceAxis("http://www.qdhtxxrd.com:7788/api/plat/xxfp/service/CommService?wsdl",
        // "http://webservice.xxfp.plat.yshs.aisino.com/", "DLSBService", param);
        // System.out.println("respXML:" + respXML);

    }

    /**
     * axis调用webservice服务
     *
     * @param wsdlURL
     * @param methodName
     * @param param
     * @return
     */
    public static String callWebServiceAxis(String wsdlURL, String nameSpace, String methodName, String param) {
        try {
            // 直接引用远程的wsdl文件
            Service service = new Service();
            Call call = (Call)service.createCall();
            call.setTargetEndpointAddress(wsdlURL);
            call.setOperationName(new QName(nameSpace, methodName));// 调用的方法名
            call.addParameter("arg0", org.apache.axis.encoding.XMLType.XSD_DATE, javax.xml.rpc.ParameterMode.IN);// 接口的参数
            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);// 设置返回类型
            String result = (String)call.invoke(new Object[] {param});// 给方法传递参数，并且调用方法
            return result;
        } catch (Exception e) {
            return e.toString();
        }
    }
}
